package com.waidi.clothespad.ui;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import com.waidi.clothespad.R;
import com.waidi.clothespad.adapter.StyleNumInfoAdapter;
import com.waidi.clothespad.common.Config;
import com.waidi.clothespad.common.MessageToUi;
import com.waidi.clothespad.common.MyToast;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class StyleNumSizeInfoDialog extends Dialog
{
    private View view;
    private static final String TAG = StyleNumSizeInfoDialog.class.getName();
    private Context context;
    private Handler handler0;
    private StyleNumInfoAdapter styleNumInfoAdapter = null;
    private GridView gridView = null;
    Button bt_ok;

    public StyleNumSizeInfoDialog(@NonNull Context context, Handler handlerin) {
        super(context);
        this.context = context;
        this.handler0 = handlerin;
        init();
    }
    public StyleNumSizeInfoDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //init();
    }

    private void init()
    {

        View view = LayoutInflater.from(context).inflate(R.layout.layer_stylenum_info, null);
        setContentView(view);
            //
        gridView = (GridView) view.findViewById(R.id.gridView_StyleNumInfo);
     /*       List<String> name = new ArrayList<>();
            for(int i=0;i<200;i++)
            {
                name.add("101");
            }

            styleNumInfoAdapter = new StyleNumInfoAdapter(context,name);
            gridView.setAdapter(styleNumInfoAdapter);
            styleNumInfoAdapter.notifyDataSetChanged();*/
            //
        this.getWindow().setDimAmount(Config.transparency);
        Window dialogWindow = getWindow();
        WindowManager manager = ((Activity) context).getWindowManager();
        WindowManager.LayoutParams params = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        dialogWindow.setGravity(Gravity.CENTER);//设置对话框位置
        Display d = manager.getDefaultDisplay(); // 获取屏幕宽、高度
        params.width = (int) (d.getWidth() * 0.65); // 宽度设置为屏幕的0.65，根据实际情况调整
        params.height = (int) (d.getHeight() * 0.75); // 宽度设置为屏幕的0.65，根据实际情况调整
        dialogWindow.setAttributes(params);

        bt_ok = (Button) view.findViewById(R.id.bt_ok);
        bt_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });



    }

    public void update(List<String> data,int colum)
    {
        try
        {
            gridView.setNumColumns(colum);
            styleNumInfoAdapter = new StyleNumInfoAdapter(context,data);
            gridView.setAdapter(styleNumInfoAdapter);
            styleNumInfoAdapter.notifyDataSetChanged();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
